const crypto = require('crypto');

const password = Buffer.from('https://www.9-cloud.com.cn/2021/', 'utf8')
const iv = Buffer.from('FnJL7EDzjqWjcaY9', 'utf8')

const Encrypt = (decrypted, key = password) => {
  const cipher = crypto.createCipheriv('aes-256-cbc', key, iv)
  let encrypted = cipher.update(decrypted, 'utf8', 'hex')
  encrypted += cipher.final('hex')
  return encrypted
}

const Decrypt = (encrypted, key = password) => {
  const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv)
  let decrypted = decipher.update(encrypted, 'hex', 'utf8')
  decrypted += decipher.final('utf8')
  return decrypted
}

module.exports = {
  Encrypt,
  Decrypt
}